﻿//送检页面JS

function gocheck(hardid) {
    $("#hidHardid").val(hardid);
    //取值
    $.ajax({
        type: "post",
        url: "/ashx/HardWare.ashx",
        data: {
            rType: 'm'
                   , mid: hardid
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert(XmlHttpRequest.status);
            alert("提交失败！")
        },
        success: function (msg) {
            //值显示
            var o = eval('(' + msg + ')');
            $("#lblno").html(o.hardwareno);
            $("#lblcjo").html(o.cjono);
            $("#lblload").html(o.loadno);
            $("#lblcumname").html(o.cumname);
            $("#lblman").html(o.saleman);
            $("#lblcjoremark").html(o.cjoremark);
            $("#lblcolldate").html(o.wrldate);
            $("#lblcount").html(o.boxcount);
            $("#lblbcity").html(o.bcity);
            $("#lblgcity").html(o.gcity);
            $("#txtGoCheckMemo").val(o.txtGoCheckMemo);
            var myDate = new Date();
            $("#lblgodate").html(myDate.toLocaleDateString());
            //弹出框
            $("#tabreord").dialog({
                width: 400,
                height: 300,
                resizable: false,
                position: 'center',
                title: "送检",
                modal: true,
                close: function (event, ui) {
                    location.reload();
                }
            });
        }
    });


}



//维护
function updaterecord(hardid) {
    $("#hidHardid").val(hardid);
    //取值
    $.ajax({
        type: "post",
        url: "/ashx/HardWare.ashx",
        data: {
            rType: 'm'
                   , mid: hardid
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert(XmlHttpRequest.status);
            alert("提交失败！")
        },
        success: function (msg) {
            //值显示
            var o = eval('(' + msg + ')');
            $("#txtcjo").val(o.cjono);
            $("#lblupdateno").html(o.hardwareno);
            $("#txtload").val(o.loadno);
            $("#txtcumname").val(o.cumname);
            $("#txtman").val(o.saleman);
            $("#txtcjoremark").val(o.cjoremark);
            $("#colldate").val(o.wrldate);
            $("#txtcount").val(o.boxcount);
            $("#dropbcity").val(o.bcity);
            $("#dropgcity").val(o.gcity);
            if (o.wrlid > 0) {

                $("#txtcjo").attr("disabled", "disabled");
                $("#lblupdateno").attr("disabled", "disabled");
                $("#txtload").attr("disabled", "disabled");
                $("#txtcumname").attr("disabled", "disabled");
                $("#txtman").attr("disabled", "disabled");
                $("#colldate").attr("disabled", "disabled");
                $("#txtcount").attr("disabled", "disabled");
                $("#dropbcity").attr("disabled", "disabled");
                $("#dropgcity").attr("disabled", "disabled");
                $("#btnSave").attr("style", "display:none;");
                $("#btnCancel").html("关闭");
                //$("#txtwrlid").val(o.wrlid);
                $("#txtcjoremark").attr("disabled", "disabled");
            }

            //弹出框
            $("#tabnew").dialog({
                width: 400,
                height: 300,
                resizable: false,
                position: 'center',
                title: "控制表维护",
                //            dialogClass: "noClose",
                modal: true
            });
        }
    });


}



//送检弹出提交
function gocheckSubmit() {
    var checkstatus = $("#gotype").val();
    if (checkstatus == "0") {
        alert("请选择送检部门");

        return;
    } else {
        $.ajax({
            type: "post",
            url: "/ashx/HardWare.ashx",
            data: {
                rType: "Hard"
                , checkstatus: checkstatus
                , checkdate: $("#lblgodate").html()
                , hardid: $("#hidHardid").val()
                , gomemo: $("#txtGoCheckMemo").val()
                , step1: checkstatus
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert(XmlHttpRequest.status);
                alert("提交失败！")
            },
            success: function (msg) {
                alert("已经送检");
                location.reload();
            }
        });
    }


}

$(document).ready(function () {

    $("#rdoinit,#rdohard,#rdoC,#rdoSale").click(function () {
        if ($(this).attr('id') == 'rdoinit') {
            $("#gotype").val("1");
        }
        else if ($(this).attr('id') == 'rdohard') {
            $("#gotype").val("2");
        }
        else if ($(this).attr('id') == 'rdoC') {    //拆解出库
            $("#gotype").val("3");
        }
        else if ($(this).attr('id') == 'rdoSale') {//销售
            $("#gotype").val("4");
        }

    });

    $('#tab').dataTable({ "oLanguage":
                 { "sUrl": "/jquery/jquery.dataTable.cn.txt" },
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        'bPaginate': true,
        "bProcessing": true,
        "iDisplayLength": 20,
        "bSort": true,
        "aaSorting": [[0, "desc"]]
    });

    $("#tabnew").hide();
    $("#tabreord").hide();

    $("#btnnew").click(function () {
        //新增
        $("#tabnew").dialog({
            width: 400,
            height: 300,
            resizable: false,
            position: 'center',
            title: "新增控制表",
            //            dialogClass: "noClose",
            modal: true
        });
    });


    $("#btnSave").click(function () {

        var bcity = $('option:selected', '#dropbcity').index();
        var gcity = $('option:selected', '#dropgcity').index();
        if (bcity == 0) {
            alert("请选择归属地");
            return;
        }
        if (gcity == 0) {
            alert("请选择处理地");
            return;
        }
        if ($("#txtload").val().trim() == "") {
            alert("load不能为空");
            return;
        }
        if ($("#txtcjo").val().trim() == "") {
            alert("cjo不能为空");
            return;
        }
        if ($("#txtcjoremark").val().trim() == "") {
            alert("cjo备注不能为空");
            return;
        }
        if ($("#txtcount").val().trim() == "") {
            alert("托数不能为空");
            return;
        }
        if ($("#colldate").val().trim() == "") {
            alert("收货日期不能为空");
            return;
        }
        if ($("#txtcumname").val().trim() == "") {
            alert("客户名不能为空");
            return;
        }




        $.ajax({
            type: "post",
            url: "/ashx/HardWare.ashx?rType=Hard",
            data: {
                iotype: "Add"
                        , txtcjo: $("#txtcjo").val()
                        , txtload: $("#txtload").val()
                        , txtcjoremark: $("#txtcjoremark").val()
                        , txtcount: $("#txtcount").val()
                        , txtcumname: $("#txtcumname").val()
                        , txtman: $("#txtman").val()
                        , txtwrldate: $("#colldate").val()
                        , bcity: $("#dropbcity").val()
                        , gcity: $("#dropgcity").val()
                        , hardid: $("#hidHardid").val()
                        , step1: 0
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert(XmlHttpRequest.status);
                alert("提交失败！请联系管理员或者重新扫描条码出库。")
            },
            success: function (msg) {
                alert("新增完成");
                location.reload();
            }
        });
    });

    //var obj = eval('(' + msg + ')');
    $("#btnCancel").click(function () {
        cancel();
    });

    $("#colldate").datepicker({
        "dateFormat": "yy-mm-dd"
    });

    function cancel() {
        location.reload();
    }

});
